﻿using Framework;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace SchemaMonitor.xml
{
    public class CSmsList : List<CSms>
    {
        //public CSmsList(DataSet ds) : this(ds.Tables[0]) { }
        //public CSmsList(DataTable dt) : base(dt.Rows.Count)
        //{
        //    foreach (var i in dt.Rows)
        //        Add(new CSms(i));
        //}

        public CSmsList(XmlNode smses) : base(CXml.AttributeInt(smses, "count"))
        {
            //Set #1
            foreach (var i in CXml.ChildNodes(smses, "sms"))
                this.Add(new CSms(i));

            //Set #2
            foreach (var i in CXml.ChildNodes(smses, "mms"))
                this.Add(new CMms(i));
        }




        public static CSmsList Load(string filePath = "c:\\dev\\sms-20170615153638.xml")
        {
            var doc = new XmlDocument();
            var xml = File.ReadAllText(filePath);
            doc.LoadXml(xml);
            return new CSmsList(doc.DocumentElement);
        }

        public List<int> SaveAll()
        {
            var ids = new List<int>();
            foreach (var i in this)
                ids.Add(i.Save());
            return ids;
        }
    }
}
